<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>coDing</title>
    <link rel="shortcut icon" href="img/favicon.ico">
</head>

<body>
<div style="margin: 20px auto; max-width: 900px;">
    <h2>【coDing】提醒您：</h2>
    <p><span id="timeshow"></span>工作再累，一定不要忘记摸鱼哦！有事没事起身去茶水间，去厕所，去廊道走走别老在工位上坐着，钱是老板的,但命是自己的。</p>
    <ul id="favs"></ul>
    <p>
        上班是帮老板赚钱，摸鱼是赚老板的钱！最后，祝愿天下所有摸鱼人，都能愉快的渡过每一天…
    </p>
    <p>
        【友情提示】三甲医院ICU躺一天平均费用大概一万块，你晚一天进ICU，就等于为你的家庭多赚一万块。少上班，多摸鱼。
    </p>

</div>

<script>
    var CalendarData = new Array(20);
    var madd = new Array(12);
    var TheDate;
    var tgString = "甲乙丙丁戊己庚辛壬癸";
    var dzString = "子丑寅卯辰巳午未申酉戌亥";
    var numString = "一二三四五六七八九十";
    var monString = "正二三四五六七八九十冬腊";
    var weekString = "日一二三四五六";
    var sx = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
    var cYear;
    var cMonth;
    var cDay;
    var cHour;
    var cDateString;
    var DateString;
    var Browser = navigator.appName;

    function init() {
        CalendarData[0] = 0x41A95; //公元2001年;
        CalendarData[1] = 0xD4A;
        CalendarData[2] = 0xDA5;
        CalendarData[3] = 0x20B55;
        CalendarData[4] = 0x56A;
        CalendarData[5] = 0x7155B;
        CalendarData[6] = 0x25D;
        CalendarData[7] = 0x92D;
        CalendarData[8] = 0x5192B;
        CalendarData[9] = 0xA95;
        CalendarData[10] = 0xB4A;
        CalendarData[11] = 0x416AA;
        CalendarData[12] = 0xAD5;
        CalendarData[13] = 0x90AB5;
        CalendarData[14] = 0x4BA;
        CalendarData[15] = 0xA5B;
        CalendarData[16] = 0x60A57;
        CalendarData[17] = 0x52B;
        CalendarData[18] = 0xA93;
        CalendarData[19] = 0x40E95;
        madd[0] = 0;
        madd[1] = 31;
        madd[2] = 59;
        madd[3] = 90;
        madd[4] = 120;
        madd[5] = 151;
        madd[6] = 181;
        madd[7] = 212;
        madd[8] = 243;
        madd[9] = 273;
        madd[10] = 304;
        madd[11] = 334; //今年某月已过天数！
    }

    function GetBit(m, n) {
        return (m >> n) & 1;
    } //n月是大月还是小月?
    function getInfo() { //用户输入日期！
        var arr = [];
        var now = new Date()
        strData = now.toISOString().substr(0, 10)
        if (strData == null || strData == "") {
            alert("输入错误！请刷新！");
            return false;
        }
        arr = strData.split("-");
        y = arr[0];
        m = arr[1] - 1;
        d = arr[2];
        TheDate = new Date(y, m, d);
    } //getinfo();
    function e2c() {
        getInfo();
        var total, m, n, k;
        var isEnd = false;
        var tmp = TheDate.getYear();
        if (tmp < 1900) tmp += 1900; //无用！
        total = (tmp - 2001) * 365 + Math.floor((tmp - 2001) / 4) + madd[TheDate.getMonth()] + TheDate.getDate() -
            23; //2001年1月23是除夕;该句计算到起始年正月初一的天数
        if (TheDate.getYear() % 4 == 0 && TheDate.getMonth() > 1) total++; //当年是闰年且已过2月再加一天！
        for (m = 0;; m++) {
            k = (CalendarData[m] < 0xfff) ? 11 : 12; //起始年+m闰月吗？
            for (n = k; n >= 0; n--) {
                if (total <= 29 + GetBit(CalendarData[m], n)) //已找到农历年!
                {
                    isEnd = true;
                    break;
                }
                total = total - 29 - GetBit(CalendarData[m], n); //寻找农历年！
            }
            if (isEnd) break;
        }
        cYear = 2001 + m; //农历年
        cMonth = k - n + 1; //农历月
        cDay = total; //农历日
        if (k == 12) //闰年！
        {
            if (cMonth == Math.floor(CalendarData[m] / 0x10000) + 1) //该月就是闰月！
                cMonth = 1 - cMonth;
            if (cMonth > Math.floor(CalendarData[m] / 0x10000) + 1) cMonth--; //该月是闰月后某个月！
        }
        cHour = Math.floor((TheDate.getHours() + 1) / 2);
    }

    function GetcDateString() {
        var tmp = "";
        tmp += tgString.charAt((cYear - 4) % 10);
        //年干
        tmp += dzString.charAt((cYear - 4) % 12); //年支
        tmp += "年(";
        tmp += sx.charAt((cYear - 4) % 12);
        tmp += ")";
        if (cMonth < 1) {
            tmp += "闰";
            tmp += monString.charAt(-cMonth - 1); // 闰几月！
        } else tmp += monString.charAt(cMonth - 1);
        tmp += "月";
        tmp += (cDay < 11) ? "初" : ((cDay < 20) ? "十" : ((cDay < 30) ? "廿" : "卅")); // 初几！
        if (cDay % 10 != 0 || cDay == 10) tmp += numString.charAt((cDay - 1) % 10);
        if (cHour == 12) tmp += "夜";
        tmp += dzString.charAt((cHour) % 12);
        tmp += "时"; //几时！
        cDateString = tmp;
        return tmp;
    }

    function GetDateString() //公历时间！
    {
        var tmp = "";
        var t1 = TheDate.getYear();
        if (t1 < 1900) t1 += 1900;
        tmp += t1 + "-" + (TheDate.getMonth() + 1) + "-" + TheDate.getDate() + " " + TheDate.getHours() + ":" + ((
            TheDate.getMinutes() < 10) ? "0" : "") + TheDate.getMinutes() + " 星期" + weekString.charAt(TheDate
            .getDay());
        DateString = tmp;
        return tmp;
    }

    function cnCanlender() {
        init();
        e2c();
        GetDateString();
        GetcDateString();
        // strcnCanlender.innerText = DateString + "\n" + cDateString; //显示！
        timeshow.innerText =
            `阳历：${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日 ${DateString.substr(-3)}\n农历：${cDateString.slice(0,-2)}\n${now.getHours() < 11 ? '上午' : now.getHours() > 17 ? '晚上' : '上午'}好，打工人\n`


    }
</script>
<script>
    const FAVS = ['元旦', '劳动节', '国庆节', '春节', '清明', '端午', '中秋']
    const arr = [0, 0, 46, 3, 94, 4, 120, 1, 168, 5, 266, 6, 273, 2, 365, 0, 400, 3, 459, 4, 485, 1, 522, 5, 620, 6,
        638, 2, 730, 0, 754, 3, 824, 4, 851, 1, 906, 5, 1004, 2, 1004, 6, 1096, 0, 1138, 3, 1189, 4, 1216, 1,
        1260, 5, 1359, 6, 1369, 2, 1461, 0, 1492, 3, 1555, 4, 1581, 1, 1614, 5, 1713, 6, 1734, 2, 1826, 0, 1847,
        3, 1920, 4, 1946, 1, 1998, 5, 2097, 6, 2099, 2, 2191, 0, 2231, 3, 2285, 4, 2312, 1, 2352, 5, 2451, 6,
        2465, 2, 2557, 0, 2585, 3, 2650, 4, 2677, 1, 2707, 5, 2830, 2, 2835, 6
    ];
    const getResult = (_n) => {
        const n = Math.floor((_n - 1514736000000) / 86400000)
        for (let i = 0; i < arr.length; i += 2) {
            if (arr[i] >= n) {
                const result = new Array()
                for (let j = 0; j < 14; j += 2) {
                    const m = arr[i + j]
                    result.push([m - n, arr[i + j + 1]])
                }
                return result
            }
        }
        return []
    }

    const now = new Date()
    favs.innerHTML = `<li>距离周末还有:${5 - now.getDay()<0? 0:5 - now.getDay()}天</li>`

    console.log(getResult(now))
    favs.innerHTML += getResult(now).map(([a, b]) => `<li>距离${FAVS[b]}还有:${a}天</li>`).join('\n')
    cnCanlender()
</script>
</body>

</html>
